package com.kotlin.lib.coroutines

import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.async
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking

fun main() = runBlocking<Unit> {
    val job = GlobalScope.launch {
        println("Throwing exception from launch")
        throw IndexOutOfBoundsException()
    }
    job.join()
    println("Join failed job")

    val async = GlobalScope.async {
        println("Throwing exception from async")
        throw ArithmeticException()
    }
    try {
        async.await()
    } catch (e: Exception) {
        println("caught exception:${e::class}")
    }
}